package avicit.im.lantop.userauthset.rest;


import avicit.cbb.businessclass.system.dataauth.domain.CbbAuthResource;
import avicit.im.lantop.basic.fieldmapset.action.rest.LantopFieldMapSetServiceRest;
import avicit.im.lantop.userauthset.domain.LantopQualificationDetail;
import avicit.im.lantop.userauthset.domain.LantopUserAuthCondition;
import avicit.im.lantop.userauthset.domain.LantopUserAuthExtendData;
import avicit.im.lantop.userauthset.domain.LantopUserAuthSetExtend;
import avicit.im.lantop.userauthset.service.UserAuthService;
import avicit.im.lantop.userauthset.service.api.UserAuthServiceApi;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.jdbc.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "UserAuthService", description = "UserAuth_Service")
@RequestMapping("/api/avicit/im/lantop/userauthset/rest/UserAuthServiceRest")
public class UserAuthServiceRest {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserAuthServiceRest.class);


    @Autowired(required = true)
    private UserAuthService userAuthService;


    /**
     * 根据ids获取用户权限设置数据
     * @param map
     * @return
     */
    @PostMapping("/getUsers")
    @ApiOperation(value = "通过数据id获得附件id")
    public ResponseMsg getUsers(@ApiParam(value = "通过数据id获得附件id", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String userName = (String) map.get("userName");
            String orgId = (String) map.get("orgId");
            String id = (String) map.get("id");
            userAuthService.getUsers(page, userName,orgId,id);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取用户权限设置信息数量：用于判断是否可以批量设置操作权限
     * @param map
     * @return
     */
    @PostMapping("/getLantopUserAuthSetExtendByResourceId")
    @ApiOperation(value = "获取用户权限设置信息数量：用于判断是否可以批量设置操作权限")
    public ResponseMsg<Integer> getLantopUserAuthSetExtendByResourceId(@ApiParam(value = "获取用户权限设置信息数量：用于判断是否可以批量设置操作权限", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        try {
            String cbbAuthResourceIds = (String) map.get("cbbAuthResourceIds");
            int lantopUserAuthSetExtendByResourceId = userAuthService.getLantopUserAuthSetExtendByResourceId(cbbAuthResourceIds);
            responseMsg.setResponseBody(lantopUserAuthSetExtendByResourceId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 加载不包含relTargetId的操作权限分类
     * @param map
     * @return
     */
    @PostMapping("/getLantopOperateClassList")
    @ApiOperation(value = "加载不包含relTargetId的操作权限分类")
    public ResponseMsg<List<Map<String, Object>>> getLantopOperateClassList(@ApiParam(value = "加载不包含relTargetId的操作权限分类", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String relTargetId = (String) map.get("relTargetId");
            List<Map<String, Object>> lantopOperateClassList = userAuthService.getLantopOperateClassList(relTargetId);
            responseMsg.setResponseBody(lantopOperateClassList);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存新增条件
     * @param map
     * @return
     */
    @PostMapping("/saveQualification")
    @ApiOperation(value = "保存新增条件")
    public ResponseMsg saveQualification(@ApiParam(value = "保存新增条件", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            userAuthService.saveQualification(param);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 保存用户权限设置条件扩展信息
     * @param map
     * @return
     */
    @PostMapping("/insertLantopUserAuthConditions")
    @ApiOperation(value = "保存用户权限设置条件扩展信息")
    public ResponseMsg insertLantopUserAuthConditions(@ApiParam(value = "保存用户权限设置条件扩展信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            List<LantopUserAuthCondition> luacs = (List<LantopUserAuthCondition>) map.get("luacs");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            userAuthService.insertLantopUserAuthConditions(luacs, parameter);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *保存条件权限明细信息
     * @param map
     * @return
     */
    @PostMapping("/saveLantopQualificationDetail")
    @ApiOperation(value = "保存条件权限明细信息")
    public ResponseMsg saveLantopQualificationDetail(@ApiParam(value = "保存条件权限明细信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> qualificationDetailList = (List<Map<String, Object>>) map.get("qualificationDetailList");
            Map<String, String> param2 = (Map<String, String>) map.get("param2");
            userAuthService.saveLantopQualificationDetail(qualificationDetailList, param2);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *加载操作权限分类
     * @param map
     * @return
     */
    @PostMapping("/getSetOperatreClass")
    @ApiOperation(value = "加载操作权限分类")
    public ResponseMsg getSetOperatreClass(@ApiParam(value = "加载操作权限分类", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String relTargetId = (String) map.get("relTargetId");
            userAuthService.getSetOperatreClass(page, relTargetId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 根据ids获取用户权限设置数据
     * @param map
     * @return
     */
    @PostMapping("/getCbbAuthResourceDatasByNodeId")
    @ApiOperation(value = "根据ids获取用户权限设置数据")
    public ResponseMsg<List<Map<String, Object>>> getCbbAuthResourceDatasByNodeId(@ApiParam(value = "根据ids获取用户权限设置数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            List<Map<String, Object>> cbbAuthResourceDatasByNodeId = userAuthService.getCbbAuthResourceDatasByNodeId(param);
            responseMsg.setResponseBody(cbbAuthResourceDatasByNodeId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 加载用户权限设置信息扩展对象
     * @param map
     * @return
     */
    @PostMapping("/getLantopUserAuthSetExtend")
    @ApiOperation(value = "加载用户权限设置信息扩展对象")
    public ResponseMsg<LantopUserAuthSetExtend> getLantopUserAuthSetExtend(@ApiParam(value = "加载用户权限设置信息扩展对象", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<LantopUserAuthSetExtend> responseMsg = new ResponseMsg<>();
        try {
            String cbbAuthResourceId_search = (String) map.get("cbbAuthResourceId_search");
            LantopUserAuthSetExtend lantopUserAuthSetExtend = userAuthService.getLantopUserAuthSetExtend(cbbAuthResourceId_search);
            responseMsg.setResponseBody(lantopUserAuthSetExtend);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除用户权限设置信息扩展记录
     * @param map
     * @return
     */
    @PostMapping("/delLantopUserAuthSetExtend")
    @ApiOperation(value = "删除用户权限设置信息扩展记录")
    public ResponseMsg delLantopUserAuthSetExtend(@ApiParam(value = "删除用户权限设置信息扩展记录", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            userAuthService.delLantopUserAuthSetExtend(id);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 新增用户权限设置信息扩展记录
     * @param map
     * @return
     */
    @PostMapping("/insertLantopUserAuthSetExtend")
    @ApiOperation(value = "新增用户权限设置信息扩展记录")
    public ResponseMsg insertLantopUserAuthSetExtend(@ApiParam(value = "新增用户权限设置信息扩展记录", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopUserAuthSetExtend newLantopUserAuthSetExtend = (LantopUserAuthSetExtend) map.get("newLantopUserAuthSetExtend");
            userAuthService.insertLantopUserAuthSetExtend(newLantopUserAuthSetExtend);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 获取不包含用户ID为targetId的所有用户
     * @param map
     * @return
     */
    @PostMapping("/getAllUser")
    @ApiOperation(value = "获取不包含用户ID为targetId的所有用户")
    public ResponseMsg getAllUser(@ApiParam(value = "获取不包含用户ID为targetId的所有用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String targetId = (String) map.get("targetId");
            Map<String, Object> searchMap = (Map<String, Object>) map.get("searchMap");
            userAuthService.getAllUser(page, targetId, searchMap);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 获取targetId用户所有权限记录
     * @param map
     * @return
     */
    @PostMapping("/getLantopUserAuthSetExtend/v1")
    @ApiOperation(value = "获取targetId用户所有权限记录")
    public ResponseMsg<List<LantopUserAuthSetExtend>> getLantopUserAuthSetExtend2(@ApiParam(value = "获取targetId用户所有权限记录", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<LantopUserAuthSetExtend>> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String sysId = (String) map.get("sysId");
            String targetId = (String) map.get("targetId");
            List<LantopUserAuthSetExtend> lantopUserAuthSetExtend = userAuthService.getLantopUserAuthSetExtend(orgId, deptId, sysId, targetId);
            responseMsg.setResponseBody(lantopUserAuthSetExtend);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *获取targetId用户所有权限记录
     * @param map
     * @return
     */
    @PostMapping("/getLantopUserAuthExtendData")
    @ApiOperation(value = "获取targetId用户所有权限记录")
    public ResponseMsg<List<LantopUserAuthExtendData>> getLantopUserAuthExtendData(@ApiParam(value = "获取targetId用户所有权限记录", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<LantopUserAuthExtendData>> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String sysId = (String) map.get("sysId");
            String targetId = (String) map.get("targetId");
            List<LantopUserAuthExtendData> lantopUserAuthExtendData = userAuthService.getLantopUserAuthExtendData(orgId, deptId, sysId, targetId);
            responseMsg.setResponseBody(lantopUserAuthExtendData);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存复制到目标用户
     * @param map
     * @return
     */
    @PostMapping("/saveCopyToTargetUser")
    @ApiOperation(value = "保存复制到目标用户")
    public ResponseMsg saveCopyToTargetUser(@ApiParam(value = "保存复制到目标用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String sysId = (String) map.get("sysId");
            List<LantopUserAuthSetExtend> lantopUserAuthSetExtends = (List<LantopUserAuthSetExtend>) map.get("lantopUserAuthSetExtends");
            List<LantopUserAuthExtendData> lantopUserAuthExtendDatas = (List<LantopUserAuthExtendData>) map.get("lantopUserAuthExtendDatas");
            List<CbbAuthResource> cbbAuthResources = (List<CbbAuthResource>) map.get("cbbAuthResources");
            String targetUserIds = (String) map.get("targetUserIds");
            userAuthService.saveCopyToTargetUser(orgId, deptId, sysId, lantopUserAuthSetExtends, lantopUserAuthExtendDatas, cbbAuthResources, targetUserIds);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存复制到目标用户(保存授权资源信息,更新用户权限设置信息扩展)
     * @param map
     * @return
     */
    @PostMapping("/saveCbbAuthResourceAndUpdateSetExtendByUserIds")
    @ApiOperation(value = "保存复制到目标用户(保存授权资源信息,更新用户权限设置信息扩展)")
    public ResponseMsg saveCbbAuthResourceAndUpdateSetExtendByUserIds(@ApiParam(value = "保存复制到目标用户(保存授权资源信息,更新用户权限设置信息扩展)", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String targetId = (String) map.get("targetId");
            List<CbbAuthResource> cbbAuthResources = (List<CbbAuthResource>) map.get("cbbAuthResources");
            String targetUserIds = (String) map.get("targetUserIds");
            userAuthService.saveCbbAuthResourceAndUpdateSetExtendByUserIds(orgId, deptId, targetId, cbbAuthResources, targetUserIds);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取用户下的所有节点  (20160711 add wangzp)
     * @param map
     * @return
     */
    @PostMapping("/getClassNodeIds")
    @ApiOperation(value = "获取用户下的所有节点  (20160711 add wangzp)")
    public ResponseMsg<String> getClassNodeIds(@ApiParam(value = "获取用户下的所有节点  (20160711 add wangzp)", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String targetId = (String) map.get("targetId");
            String sysId = (String) map.get("sysId");
            userAuthService.getClassNodeIds(orgId, deptId, sysId, targetId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除复制权限数据(数据回滚操作)
     * @param map
     * @return
     */
    @PostMapping("/deleteAuthCopyDataByRollBack")
    @ApiOperation(value = "删除复制权限数据(数据回滚操作)")
    public ResponseMsg deleteAuthCopyDataByRollBack(@ApiParam(value = "删除复制权限数据(数据回滚操作)", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String targetId = (String) map.get("targetId");
            String targetUserIds = (String) map.get("targetUserIds");
            userAuthService.deleteAuthCopyDataByRollBack(orgId, deptId, targetId, targetUserIds);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 加载档案数据
     * @param map
     * @return
     */
    @PostMapping("/getArchiveClass")
    @ApiOperation(value = "加载档案数据")
    public ResponseMsg<List<Map<String, Object>>> getArchiveClass(@ApiParam(value = "加载档案数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            userAuthService.getArchiveClass(param);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取条件权限明细
     * @param map
     * @return
     */
    @PostMapping("/getLantopQualificationDetails")
    @ApiOperation(value = "获取条件权限明细")
    public ResponseMsg<List<LantopQualificationDetail>> getLantopQualificationDetails(@ApiParam(value = "获取条件权限明细", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<LantopQualificationDetail>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            List<LantopQualificationDetail> lantopQualificationDetails = userAuthService.getLantopQualificationDetails(id);
            responseMsg.setResponseBody(lantopQualificationDetails);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 获取角色信息
     * @param map
     * @return
     */
    @PostMapping("/getUserRoleList")
    @ApiOperation(value = "获取角色信息")
    public ResponseMsg getUserRoleList(@ApiParam(value = "获取角色信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String name = (String) map.get("name");
            String orgId = (String) map.get("orgId");
            userAuthService.getUserRoleList(page, name,orgId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存条件权限明细
     * @param map
     * @return
     */
    @PostMapping("/saveLantopQualifcicationDetail")
    @ApiOperation(value = "保存条件权限明细")
    public ResponseMsg saveLantopQualifcicationDetail(@ApiParam(value = "保存条件权限明细", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopQualificationDetail lantopQualificationDetail = (LantopQualificationDetail) map.get("lantopQualificationDetail");
            userAuthService.saveLantopQualifcicationDetail(lantopQualificationDetail);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除条件权限明细信息
     * @param map
     * @return
     */
    @PostMapping("/delLantopQualificationDetail")
    @ApiOperation(value = "删除条件权限明细信息")
    public ResponseMsg delLantopQualificationDetail(@ApiParam(value = "删除条件权限明细信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            userAuthService.delLantopQualificationDetail(id);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 加载电子文件待选择条目
     * @param map
     * @return
     */
    @PostMapping("/getElectronicWaitSelectEntry")
    @ApiOperation(value = "加载电子文件待选择条目")
    public ResponseMsg getElectronicWaitSelectEntry(@ApiParam(value = "加载电子文件待选择条目", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            userAuthService.getElectronicWaitSelectEntry(page, param);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *
     * @param map
     * @return
     */
    @PostMapping("/getNotElectronicWaitSelectEntry")
    @ApiOperation(value = "加载电子文件待选择条目")
    public ResponseMsg getNotElectronicWaitSelectEntry(@ApiParam(value = "加载电子文件待选择条目", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            userAuthService.getNotElectronicWaitSelectEntry(page, param);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 加载已设置权限条目
     * @param map
     * @return
     */
    @PostMapping("/getAuthEntry")
    @ApiOperation(value = "加载已设置权限条目")
    public ResponseMsg getAuthEntry(@ApiParam(value = "加载已设置权限条目", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            userAuthService.getAuthEntry(page, param);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存条目权限设置
     * @param map
     * @return
     */
    @PostMapping("/saveAuthEntry")
    @ApiOperation(value = "保存条目权限设置")
    public ResponseMsg saveAuthEntry(@ApiParam(value = "保存条目权限设置", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            List<LantopUserAuthExtendData> lantopUserAuthExtendDatas = (List<LantopUserAuthExtendData>) map.get("lantopUserAuthExtendDatas");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            userAuthService.saveAuthEntry(lantopUserAuthExtendDatas, parameter);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 通过节点id获取数据授权信息
     * @param map
     * @return
     */
    @PostMapping("/getUserAuthExtendDatasByNodeId")
    @ApiOperation(value = "通过节点id获取数据授权信息")
    public ResponseMsg<List<Map<String, Object>>> getUserAuthExtendDatasByNodeId(@ApiParam(value = "通过节点id获取数据授权信息", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String nodeIds = (String) map.get("nodeIds");
            List<Map<String, Object>> userAuthExtendDatasByNodeId = userAuthService.getUserAuthExtendDatasByNodeId(nodeIds);
            responseMsg.setResponseBody(userAuthExtendDatasByNodeId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除条目权限设置
     * @param map
     * @return
     */
    @PostMapping("/delAuthEntry")
    @ApiOperation(value = "删除条目权限设置")
    public ResponseMsg<List<Map<String, Object>>> delAuthEntry(@ApiParam(value = "删除条目权限设置", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            userAuthService.delAuthEntry(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 加载功能操作权限菜单树
     * @param map
     * @return
     */
    @PostMapping("/getMenuTreeNode")
    @ApiOperation(value = "加载功能操作权限菜单树")
    public ResponseMsg<List<TreeNode>> getMenuTreeNode(@ApiParam(value = "加载功能操作权限菜单树", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            List<TreeNode> menuTreeNode = userAuthService.getMenuTreeNode(id);
            responseMsg.setResponseBody(menuTreeNode);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存操作权限设置
     * @param map
     * @return
     */
    @PostMapping("/getResource")
    @ApiOperation(value = "保存操作权限设置")
    public ResponseMsg<List<Map<String, Object>>> getResource(@ApiParam(value = "保存操作权限设置", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            List<CbbAuthResource> cbbAuthResources = (List<CbbAuthResource>) map.get("cbbAuthResources");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            userAuthService.saveFuncResourceConfig(cbbAuthResources, parameter);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 加载模块下资源
     * @param map
     * @return
     */
    @PostMapping("/saveFuncResourceConfig")
    @ApiOperation(value = "加载模块下资源")
    public ResponseMsg<List<Map<String, Object>>> saveFuncResourceConfig(@ApiParam(value = "加载模块下资源", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            List<Map<String, Object>> resource = userAuthService.getResource(parameter);
            responseMsg.setResponseBody(resource);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *
     * @param map
     * @return
     */
    @PostMapping("/getUserAuthDatasByParam")
    @ApiOperation(value = "加载模块下资源")
    public ResponseMsg<List<Map<String, Object>>> getUserAuthDatasByParam(@ApiParam(value = "加载模块下资源", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> param = (Map<String, Object>) map.get("param");
            List<Map<String, Object>> userAuthDatasByParam = userAuthService.getUserAuthDatasByParam(param);
            responseMsg.setResponseBody(userAuthDatasByParam);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 取出数据结点的类型  (20160708 add wangzp)
     * @param map
     * @return
     */
    @PostMapping("/getClassNodeType")
    @ApiOperation(value = "取出数据结点的类型  (20160708 add wangzp)")
    public ResponseMsg<List<Map<String, Object>>> getClassNodeType(@ApiParam(value = "取出数据结点的类型  (20160708 add wangzp)", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            userAuthService.getClassNodeType(id);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取条件信息数量
     * @param map
     * @return
     */
    @PostMapping("/getLantopUserAuthSetExtendCount")
    @ApiOperation(value = "获取条件信息数量")
    public ResponseMsg<Integer> getLantopUserAuthSetExtendCount(@ApiParam(value = "获取条件信息数量", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        try {
            String targetType = (String) map.get("targetType");
            String targetId = (String) map.get("targetId");
            String id = (String) map.get("id");
            int lantop_auth_server_userset = userAuthService.getLantopUserAuthSetExtendCount(targetType, targetId, "LANTOP_AUTH_SERVER_USERSET", id);
            responseMsg.setResponseBody(lantop_auth_server_userset);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存权限资源配置
     * @param map
     * @return
     */
    @PostMapping("/saveResourceConfig")
    @ApiOperation(value = "保存权限资源配置")
    public ResponseMsg saveResourceConfig(@ApiParam(value = "保存权限资源配置", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            List<CbbAuthResource> cbbAuthResources = (List<CbbAuthResource>) map.get("cbbAuthResources");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            userAuthService.saveResourceConfig(cbbAuthResources, parameter);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 角色下所有用户
     * @param map
     * @return
     */
    @PostMapping("/getRoleUser")
    @ApiOperation(value = "角色下所有用户")
    public ResponseMsg getRoleUser(@ApiParam(value = "角色下所有用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String targetName = (String) map.get("targetName");
            String orgIdentity = (String) map.get("orgIdentity");
            userAuthService.getRoleUser(page, targetName,orgIdentity);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 部门下所有用户
     * @param map
     * @return
     */
    @PostMapping("/getDetpUser")
    @ApiOperation(value = "部门下所有用户")
    public ResponseMsg getDetpUser(@ApiParam(value = "部门下所有用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String targetId = (String) map.get("targetId");
            String orgIdentity = (String) map.get("orgIdentity");
            userAuthService.getDetpUser(page, targetId,orgIdentity);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据用户ID获取用户
     * @param map
     * @return
     */
    @PostMapping("/getUser")
    @ApiOperation(value = "根据用户ID获取用户")
    public ResponseMsg getUser(@ApiParam(value = "根据用户ID获取用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String targetId = (String) map.get("targetId");
            String orgIdentity = (String) map.get("orgIdentity");
            userAuthService.getUser(page, targetId,orgIdentity);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 岗位下所有用户
     * @param map
     * @return
     */
    @PostMapping("/getPositionUser")
    @ApiOperation(value = "岗位下所有用户")
    public ResponseMsg getPositionUser(@ApiParam(value = "岗位下所有用户", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            String targetId = (String) map.get("targetId");
            String orgIdentity = (String) map.get("orgIdentity");
            userAuthService.getPositionUser(page, targetId,orgIdentity);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除权限
     * @param map
     * @return
     */
    @PostMapping("/delAuthSet")
    @ApiOperation(value = "删除权限")
    public ResponseMsg delAuthSet(@ApiParam(value = "删除权限", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String deptId = (String) map.get("deptId");
            String sysId = (String) map.get("sysId");
            String targetType = (String) map.get("targetType");
            String targetId = (String) map.get("targetId");
            String codes = (String) map.get("codes");
            userAuthService.delAuthSet(orgId, deptId, sysId, targetType, targetId, codes);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *删除已设置角色
     * @param map
     * @return
     */
    @PostMapping("/delRoleSet")
    @ApiOperation(value = "删除已设置角色")
    public ResponseMsg delRoleSet(@ApiParam(value = "删除已设置角色", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopUserAuthSetExtend lantopUserAuthSetExtend = (LantopUserAuthSetExtend) map.get("lantopUserAuthSetExtend");
            String delTargetIds = (String) map.get("delTargetIds");
            String delTargetNames = (String) map.get("delTargetNames");
            userAuthService.delRoleSet(lantopUserAuthSetExtend, delTargetIds, delTargetNames);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

}
